//
//  InlandViewController.m
//  Funny
//
//  Created by dllo on 15/10/27.
//  Copyright © 2015年 King. All rights reserved.
//

#import "InlandViewController.h"

@interface InlandViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *cityArr;//城市列表

@end

@implementation InlandViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"港澳台";
    [self tableViewHandel];
}

- (NSArray *)cityArr
{
    if (!_cityArr) {
        self.cityArr = [NSMutableArray array];
    }
    return _cityArr;
}

- (UITableView *)tableView
{
    
    if (!_tableView) {
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 44) style:UITableViewStylePlain];
        self.tableView.showsVerticalScrollIndicator = NO;
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        
        //取消分割线
        self.tableView.separatorStyle = NO;
        [self.view addSubview:self.tableView];
        [self.tableView registerClass:[InlandTableViewCell class] forCellReuseIdentifier:@"cityreuse"];
    }
    return _tableView;
}

- (void)tableViewHandel
{
    [HandleData handleDataWithUrl:@"http://open.qyer.com/place/city/get_city_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&countryid=11&lat=38.87981972226579&lon=121.5419585079168&page=1&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone7%2C2&track_deviceid=357AAE6A-2231-4843-84E7-0ED164F35BDD&track_os=ios%25209.0.2&v=1" completion:^(id data) {
        NSDictionary *dic = data;
        for (NSDictionary *dic1 in [dic objectForKey:@"data"]) {
            InlandModel *model = [InlandModel modelWithDic:dic1];
            [self.cityArr addObject:model];
        }
        [self.tableView reloadData];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.cityArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    InlandTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cityreuse"];
    //设置cell无点击效果
    cell.selectionStyle = UITableViewCellEditingStyleNone;
    InlandModel *model = [self.cityArr objectAtIndex:indexPath.row];
    NSString *str = [model.photo stringByReplacingOccurrencesOfString:@"339x226" withString:@"w800"];
    [cell.cityImgView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"chartlet_image_traning@.png"]];
    cell.cnname.text = model.catename;
    cell.enname.text = model.catename_en;
    cell.footView.image = [UIImage imageNamed:@"image.png"];
    cell.cityname.text = model.catename;
    cell.beentoLabel.text = model.beenstr;
    cell.scenicLabel.text = [NSString stringWithFormat:@"主要景点:%@",model.representative];
;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    InlandModel *model = [self.cityArr objectAtIndex:indexPath.row];
    AreaViewController *area = [[AreaViewController alloc]init];
    area.cityID = model.id;
    [self.navigationController pushViewController:area animated:NO];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 210*H;
}

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
